package cn.dapeng.rpc.common.cb;

import java.util.concurrent.ConcurrentHashMap;

public class ResponseCallBackV1 {

    /**
     * key : requestId
     */
    private final static ConcurrentHashMap<Long, Runnable> mapping = new ConcurrentHashMap<>();

    public static void addCallback(Long requestId, Runnable runnable) {
        mapping.putIfAbsent(requestId, runnable);
    }

    public static void runCallback(Long requestId) {
        mapping.get(requestId).run();
        removeCallback(requestId);
    }

    public static void removeCallback(Long requestId) {
        mapping.remove(requestId);
    }

}
